package com.mystudy.atomic.booleanTest;

import static junit.framework.Assert.*;
import org.junit.Test;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * todo:
 *
 * @Author acy
 * @Date 2019/06/05
 */
public class AtomicBooleanTest {
	@Test
	public void test() throws Exception{
		AtomicBoolean atomicBoolean = new AtomicBoolean();
		assertFalse(atomicBoolean.get());
	}

	@Test
	public void test2() throws Exception{
		AtomicBoolean atomicBoolean = new AtomicBoolean(true);
		assertTrue(atomicBoolean.get());
	}

	@Test
	public void getAndSetTest() throws Exception{
		AtomicBoolean atomicBoolean = new AtomicBoolean(true);
		boolean andSet = atomicBoolean.getAndSet(false);
		assertTrue(andSet);
		assertFalse(atomicBoolean.get());
	}

	@Test
	public void compareAndSetTest() throws Exception{
		AtomicBoolean atomicBoolean = new AtomicBoolean(true);
		boolean andSet = atomicBoolean.compareAndSet(true,false);
		assertTrue(andSet);
		assertFalse(atomicBoolean.get());

	}
}
